package com.huawei.appgallery.forum.option.post.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.Xfermode;
import android.util.AttributeSet;
import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import java.math.BigDecimal;
import o.bqx;
import o.byc.g;
import o.epv;

public class PostImageView extends AppCompatImageView {
    private int ʻ;
    private RectF ʻॱ;
    private int ʼ;
    private int ʽ;
    private Paint ʽॱ;
    private Path ʾ;
    private BigDecimal ˈ;
    private Context ˊ;
    private int ˊॱ;
    private boolean ˋ;
    private int ˋॱ;
    private boolean ˎ;
    private int ˏ;
    private Xfermode ˏॱ;
    private int ͺ;
    private int ॱ;
    private int ॱˊ;
    private float[] ॱˋ;
    private RectF ॱˎ;
    private int ॱॱ;
    private float ॱᐝ;
    private int ᐝ;
    private float[] ᐝॱ;

    public PostImageView(Context context) {
        this(context, null);
    }

    public PostImageView(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public PostImageView(Context context, @Nullable AttributeSet attributeSet, int i) {
        int i2 = 0;
        super(context, attributeSet, i);
        this.ˏ = -1;
        this.ᐝ = -1;
        this.ʾ = new Path();
        this.ʽॱ = new Paint();
        this.ˈ = new BigDecimal(2);
        this.ˊ = context;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, g.ˋʻ, 0, 0);
        while (i2 < obtainStyledAttributes.getIndexCount()) {
            int index = obtainStyledAttributes.getIndex(i2);
            if (index == g.ˌॱ) {
                this.ˎ = obtainStyledAttributes.getBoolean(index, this.ˎ);
            } else if (index == g.ˊʽ) {
                this.ˋ = obtainStyledAttributes.getBoolean(index, this.ˋ);
            } else if (index == g.ˑॱ) {
                this.ॱ = obtainStyledAttributes.getDimensionPixelSize(index, this.ॱ);
            } else if (index == g.ՙ) {
                this.ˏ = obtainStyledAttributes.getColor(index, this.ˏ);
            } else if (index == g.ٴ) {
                this.ʼ = obtainStyledAttributes.getDimensionPixelSize(index, this.ʼ);
            } else if (index == g.י) {
                this.ᐝ = obtainStyledAttributes.getColor(index, this.ᐝ);
            } else if (index == g.ˋʼ) {
                this.ʽ = obtainStyledAttributes.getDimensionPixelSize(index, this.ʽ);
            } else if (index == g.ͺˎ) {
                this.ʻ = obtainStyledAttributes.getDimensionPixelSize(index, this.ʻ);
            } else if (index == g.ˏͺ) {
                this.ॱॱ = obtainStyledAttributes.getDimensionPixelSize(index, this.ॱॱ);
            } else if (index == g.ͺˏ) {
                this.ॱˊ = obtainStyledAttributes.getDimensionPixelSize(index, this.ॱˊ);
            } else if (index == g.ˎͺ) {
                this.ˋॱ = obtainStyledAttributes.getDimensionPixelSize(index, this.ˋॱ);
            }
            i2++;
        }
        obtainStyledAttributes.recycle();
        bqx.ˏ("NiceImageView", "borderWidth:" + this.ॱ);
        this.ॱˋ = new float[8];
        this.ᐝॱ = new float[8];
        this.ॱˎ = new RectF();
        this.ʻॱ = new RectF();
        this.ˏॱ = new PorterDuffXfermode(Mode.DST_IN);
        ʽ();
        ᐝ();
    }

    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        super.onSizeChanged(i, i2, i3, i4);
        this.ͺ = i;
        this.ˊॱ = i2;
        ˏ();
        ॱॱ();
    }

    protected void onDraw(Canvas canvas) {
        canvas.saveLayer(this.ʻॱ, null, 31);
        if (!this.ˎ) {
            canvas.scale((((float) ((this.ͺ - (this.ॱ * 4)) - (this.ʼ * 2))) * 1.0f) / ((float) this.ͺ), (((float) ((this.ˊॱ - (this.ॱ * 4)) - (this.ʼ * 2))) * 1.0f) / ((float) this.ˊॱ), new BigDecimal(this.ͺ).divide(this.ˈ, 3, 4).floatValue(), new BigDecimal(this.ˊॱ).divide(this.ˈ, 3, 4).floatValue());
        }
        super.onDraw(canvas);
        this.ʽॱ.reset();
        this.ʾ.reset();
        BigDecimal bigDecimal = new BigDecimal(this.ͺ);
        BigDecimal bigDecimal2 = new BigDecimal(this.ˊॱ);
        if (this.ˋ) {
            this.ʾ.addCircle(bigDecimal.divide(this.ˈ, 3, 4).floatValue(), bigDecimal2.divide(this.ˈ, 3, 4).floatValue(), this.ॱᐝ, Direction.CCW);
        } else {
            this.ʾ.addRoundRect(this.ʻॱ, this.ᐝॱ, Direction.CCW);
        }
        this.ʽॱ.setAntiAlias(true);
        this.ʽॱ.setStyle(Style.FILL);
        this.ʽॱ.setXfermode(this.ˏॱ);
        canvas.clipPath(this.ʾ);
        canvas.drawPath(this.ʾ, this.ʽॱ);
        this.ʽॱ.setXfermode(null);
        canvas.restore();
        ˎ(canvas);
    }

    private void ˎ(Canvas canvas) {
        if (this.ˋ) {
            if (this.ॱ > 0) {
                ˋ(canvas, this.ॱ, this.ˏ, this.ॱᐝ - (((float) this.ॱ) / 2.0f));
            }
            if (this.ʼ > 0) {
                ˋ(canvas, this.ʼ, this.ᐝ, (this.ॱᐝ - ((float) this.ॱ)) - (((float) this.ʼ) / 2.0f));
            }
        } else if (this.ॱ > 0) {
            ˊ(canvas, this.ॱ, this.ˏ, this.ॱˎ, this.ॱˋ);
        }
    }

    private void ˋ(Canvas canvas, int i, int i2, float f) {
        ˏ(i, i2);
        this.ʾ.addCircle(new BigDecimal(this.ͺ).divide(this.ˈ, 3, 4).floatValue(), new BigDecimal(this.ˊॱ).divide(this.ˈ, 3, 4).floatValue(), f, Direction.CCW);
        canvas.drawPath(this.ʾ, this.ʽॱ);
    }

    private void ˊ(Canvas canvas, int i, int i2, RectF rectF, float[] fArr) {
        ˏ(i, i2);
        this.ʾ.addRoundRect(rectF, fArr, Direction.CCW);
        canvas.clipPath(this.ʾ);
        canvas.drawPath(this.ʾ, this.ʽॱ);
    }

    private void ˏ(int i, int i2) {
        this.ʾ.reset();
        this.ʽॱ.setStrokeWidth((float) i);
        this.ʽॱ.setColor(i2);
        this.ʽॱ.setStyle(Style.STROKE);
    }

    private void ˏ() {
        if (!this.ˋ) {
            float floatValue = new BigDecimal(this.ॱ).divide(this.ˈ, 3, 4).floatValue();
            this.ॱˎ.set(floatValue, floatValue, ((float) this.ͺ) - floatValue, ((float) this.ˊॱ) - floatValue);
        }
    }

    private void ॱॱ() {
        if (this.ˋ) {
            this.ॱᐝ = ((float) Math.min(this.ͺ, this.ˊॱ)) / 2.0f;
            this.ʻॱ.set((((float) this.ͺ) / 2.0f) - this.ॱᐝ, (((float) this.ˊॱ) / 2.0f) - this.ॱᐝ, (((float) this.ͺ) / 2.0f) + this.ॱᐝ, (((float) this.ˊॱ) / 2.0f) + this.ॱᐝ);
            return;
        }
        this.ʻॱ.set(0.0f, 0.0f, (float) this.ͺ, (float) this.ˊॱ);
        if (this.ˎ) {
            this.ʻॱ = this.ॱˎ;
        }
    }

    private void ʽ() {
        int i = 0;
        if (!this.ˋ) {
            if (this.ʽ > 0) {
                while (i < this.ॱˋ.length) {
                    this.ॱˋ[i] = (float) this.ʽ;
                    this.ᐝॱ[i] = ((float) this.ʽ) - (((float) this.ॱ) / 2.0f);
                    i++;
                }
                return;
            }
            float[] fArr = this.ॱˋ;
            float f = (float) this.ʻ;
            this.ॱˋ[1] = f;
            fArr[0] = f;
            fArr = this.ॱˋ;
            f = (float) this.ॱॱ;
            this.ॱˋ[3] = f;
            fArr[2] = f;
            fArr = this.ॱˋ;
            float f2 = (float) this.ˋॱ;
            this.ॱˋ[5] = f2;
            fArr[4] = f2;
            fArr = this.ॱˋ;
            f2 = (float) this.ॱˊ;
            this.ॱˋ[7] = f2;
            fArr[6] = f2;
            fArr = this.ᐝॱ;
            f = ((float) this.ʻ) - (((float) this.ॱ) / 2.0f);
            this.ᐝॱ[1] = f;
            fArr[0] = f;
            float[] fArr2 = this.ᐝॱ;
            float f3 = ((float) this.ॱॱ) - (((float) this.ॱ) / 2.0f);
            this.ᐝॱ[3] = f3;
            fArr2[2] = f3;
            fArr2 = this.ᐝॱ;
            float f4 = ((float) this.ˋॱ) - (((float) this.ॱ) / 2.0f);
            this.ᐝॱ[5] = f4;
            fArr2[4] = f4;
            fArr2 = this.ᐝॱ;
            f4 = ((float) this.ॱˊ) - (((float) this.ॱ) / 2.0f);
            this.ᐝॱ[7] = f4;
            fArr2[6] = f4;
        }
    }

    private void ˋ(boolean z) {
        if (z) {
            this.ʽ = 0;
        }
        ʽ();
        ˏ();
        invalidate();
    }

    private void ᐝ() {
        if (!this.ˋ) {
            this.ʼ = 0;
        }
    }

    public void setBorderWidth(int i) {
        this.ॱ = epv.ˋ(this.ˊ, i);
        ˋ(false);
    }

    public void setBorderColor(@ColorInt int i) {
        this.ˏ = i;
        invalidate();
    }

    public void setInnerBorderWidth(int i) {
        this.ʼ = epv.ˋ(this.ˊ, i);
        ᐝ();
        invalidate();
    }

    public void setInnerBorderColor(@ColorInt int i) {
        this.ᐝ = i;
        invalidate();
    }

    public void setCornerRadius(int i) {
        this.ʽ = epv.ˋ(this.ˊ, i);
        ˋ(false);
    }

    public void setCornerTopLeftRadius(int i) {
        this.ʻ = epv.ˋ(this.ˊ, i);
        ˋ(true);
    }

    public void setCornerTopRightRadius(int i) {
        this.ॱॱ = epv.ˋ(this.ˊ, i);
        ˋ(true);
    }

    public void setCornerBottomLeftRadius(int i) {
        this.ॱˊ = epv.ˋ(this.ˊ, i);
        ˋ(true);
    }

    public void setCornerBottomRightRadius(int i) {
        this.ˋॱ = epv.ˋ(this.ˊ, i);
        ˋ(true);
    }
}
